package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.anotation.NeedLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

    //Request URL: http://localhost:8500/api/user/userListenProcess/getTrackBreakSecond/51946
	/**
	 * 根据音频id获取当前用户的播放音频的暂停时间
	 * @param trackId 音频id
	 * @return 暂停时间
	 */
	@GetMapping("/getTrackBreakSecond/{trackId}")
	@NeedLogin
	@Operation(summary = "根据音频id获取当前用户的播放音频的暂停时间")
	public Result getTrackBreakSecond(@PathVariable Long trackId){
		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.ok(breakSecond);
	}


	//Request URL: http://localhost:8500/api/user/userListenProcess/updateListenProcess
	/**
	 * 播放音频过程中，每间隔3秒记录一次播放进度，即当前播放的时间时长
	 * @param userListenProcessVo 记录信息
	 */
	@PostMapping("/updateListenProcess")
	@NeedLogin
	@Operation(summary = "播放音频过程中，每间隔3秒记录一次播放进度，即当前播放的时间时长")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.ok();
	}

	//Request URL: http://localhost:8500/api/user/userListenProcess/getLatelyTrack
	/**
	 * 获取当前用户最近播放的音频信息
	 * @return 用户最近播放的音频信息
	 */
	@GetMapping("/getLatelyTrack")
	@NeedLogin
	@Operation(summary = "获取用户最近播放的音频信息")
	public Result getLatelyTrack(){
		Map<String,Object> result = userListenProcessService.getLatelyTrack();
		return Result.ok(result);
	}




}

